﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FrmHotel
{
    public partial class FrmDenglu : Form
    {
        public FrmDenglu()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("真的要退出吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr == DialogResult.Yes)
            {
                //关闭当前窗体
                this.Close();
            }
        }
        int i = 1;
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.pictureBox1.Image = imageList1.Images[i];
            i++;
            if (this.imageList1.Images.Count <= i)
            {
                i = 0;
            }
            this.label5.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        private void FrmDenglu_Load(object sender, EventArgs e)
        {
            string sql = string.Format(@"select BranchId,BranchName from Branch");
            DataTable dt = DBHelper.SelectForTable(sql);
            DataRow dr = dt.NewRow();
            dr["BranchId"] = 0;
            dr["BranchName"] = "请选择";
            dt.Rows.InsertAt(dr, 0);
            this.comboBox1.DisplayMember = "BranchName";
            this.comboBox1.ValueMember = "BranchId";
            this.comboBox1.DataSource = dt;

        }
        public string isPM = string.Empty;
        private void button3_Click(object sender, EventArgs e)
        {
            isPM = comboBox1.SelectedValue.ToString();
            ///获取用户填写的信息
            string name = this.textBox1.Text;
            string pwd = this.textBox2.Text;
            int AdminId = Convert.ToInt32(this.comboBox1.SelectedValue);
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd))
            {
                MessageBox.Show("请输入完整信息！");
                this.textBox1.Focus();
                return;
            }
            if (AdminId==0)
            {
                MessageBox.Show("请选择正确的登录身份！");
                 return;
            }
            //链接数据库
            string sql = string.Format(@"select LoginClass from Login  where LoginName='{0}' and loginpwd='{1}' and LoginClass={2} ", name, pwd, AdminId);
            int result = Convert.ToInt32(DBHelper.SelectOne(sql));
            if (result==1)
            {
                    //登录成功！ 服务员登录
                FrmMain fm = new FrmMain();
                this.Hide();
                fm.AdminId = result;
                fm.ShowDialog();
                return;  
            }
            else if (result==2)
            {
                //登录成功！ 管理员登录
                FrmMain fm = new FrmMain();
                this.Hide();
                fm.AdminId = result;
                fm.ShowDialog();

                return; 
            }
            else
            {
                MessageBox.Show("用户名或密码错误！");
                return;
            }
        }
    }
}
